package com.hjm.friend.controller.user;

import com.hjm.common.core.constants.HttpConstants;
import com.hjm.common.core.controller.BaseController;
import com.hjm.common.core.domain.Result;
import com.hjm.common.core.domain.vo.LoginUserVO;
import com.hjm.friend.domain.user.dto.UserDTO;
import com.hjm.friend.domain.user.vo.UserDetailVO;
import com.hjm.friend.service.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController extends BaseController {

    @Autowired
    UserService userService;

    @PostMapping("/sendMsg")
    // 发送验证码
    public Result<Void> sendMsg(@RequestBody UserDTO userDTO) {
        return toResult(userService.sendMsg(userDTO));
    }

    @PostMapping("/login")
    public Result<String> login(@RequestBody UserDTO userDTO) {
        return Result.ok(userService.login(userDTO.getPhone(),userDTO.getCode()));
    }

    @GetMapping("/info")
    public Result<LoginUserVO> getUserInfo(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return userService.info(token);
    }

    @DeleteMapping("/exit")
    public Result<Void> exit(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return toResult(userService.exit(token));
    }


    @GetMapping("/detail")
    public Result<UserDetailVO> getDetail() {
        return userService.detail();
    }

    @PutMapping("/edit")
    public Result<Void> edit(@RequestBody UserDetailVO userDetailVO) {
        return toResult(userService.edit(userDetailVO));
    }

    @PutMapping("/update/headImage")
    public Result<Void> updateHeadImage(@RequestBody UserDetailVO userDetailVO) {
        return toResult(userService.updateHeadImage(userDetailVO.getHeadImage()));
    }
}
